<template>
  <div class="main" v-color="'bgkImg'">
    <dz-nav>
      <template #center><b v-color><qq>record</qq></b></template>
      <template #right>
        <div class="right-nav" v-routers="{path:'/purchasing'}">
          <img src="@/assets/images/Component3.png" alt="">
          <span><qq>Tutorial</qq></span>
        </div>
      </template>
    </dz-nav>
    <div class="top-nav">
      <div class="tips"><qq>AvailableOpportunities</qq></div>
      <img class="images" src="@/assets/images/img_opportunities.png" alt="">
      <span>{{ form.count }}/{{ form.numberOfTasks }}</span>
    </div>
    <div class="box-bottom">
      <div class="box-nab">
        <div class="item" @click="change(item)" :class="{active:active===item.id}" v-for="(item,index) in nav" :key="index">
          {{item.name}}
        </div>
      </div>
      <div class="btn-img" v-if="tableData.length<1">
        <img  src="@/assets/images/img_search_result.png" alt="">
      </div>
      <van-list
          v-else
          style="width: 100%;"
          v-model:loading="loading"
          :finished="finished"
          finished-text="Finished"
          loading-text="loading"
          error-text="error"
          @load="onLoad"
      >
        <dz-undone
            @updateItem="updateItem"
            v-if="active===1"
            v-for="(item,index) in tableData"
            :key="index"
            :item="item"/>
        <dz-process
            @updateItem="updateItem"
            v-else-if="active===2"
            v-for="(item,index) in tableData"
            :key="index"
            :item="item"/>
        <dz-order v-else-if="active===3" v-for="(item,index) in tableData" :key="index" :item="item"></dz-order>
        <dz-fail  v-else v-for="(item,index) in tableData" :key="index" :item="item"></dz-fail>
      </van-list>

    </div>
  </div>
</template>

<script>
import {delTaskOrder, getLikeTaskList, selectTaskOrder, selectTaskOrderNumByUserId} from "@/api/apiFox";
import {Toast} from "vant";
import {setItem} from "@/utils/auth";


export default {
  data(){
    return{
      active:1,
      form:{numberOfTasks:0,count:0},
      isLoading:false,
      nav:[
        {id:1,name:this.$t('Undone')},
        {id:2,name:this.$t('progress')},
        {id:3,name:this.$t('Completed')},
        {id:4,name:this.$t('Rejected')},
      ],
      tableData:[],
      finished: false,
      loading: false,
      queryParams:{
        pageSize:10,
        pageNo:1,
        status: 1
      },
    }
  },
  methods:{
    getOrder(){
      selectTaskOrderNumByUserId().then(res=>{this.form = res}).catch(err=>{})
      this.getList()
    },
    change(item){
      this.active = item.id
      this.queryParams.pageNo = 1
      this.tableData=[]
      this.finished = false
      this.queryParams.status=item.id
      this.getList()
      Toast.loading({duration:200,message:this.$t('Loading')})
    },
    getList(){
      let self = this;
      selectTaskOrder(this.queryParams).then(res=>{
        self.tableData = [...self.tableData,...res];
        self.loading = false;
        if (res.length<1){
          self.finished = true
        }
      }).catch(err=>{
        console.log(err)
      })
    },
    onLoad() {
      let self = this;
      self.loading=true;
      self.queryParams.pageNo++;
      setTimeout(()=>{
        self.getList(this.queryParams)
      },500)
    },

    updateItem(item){
      console.log(item)
      switch (item.index){
        case 1:{
          delTaskOrder(item.idw).then(res=>{
            this.getList()
          }).catch(err=>{
            console.log(err)
          })
          break
        }
        case 2:{
          window.open(item.url)
          break
        }
        case 3:{
          this.$router.push({path:'/mission'}).catch(err=>{})
          setItem('mission',item)
        }
      }
    }
  },
  mounted() {
    this.queryParams.status = this.active
    this.getOrder()
  }
}
</script>

<style scoped lang="scss">
.main{
  width: 100%;
  min-height: 100vh;
  .right-nav{
    width: 90px;
    height: 35px;
    background: #FFFFFF;
    border-radius: 20px 20px 20px 20px;
    border: 1px solid #E08821;
    box-sizing: border-box;
    margin-left: -15px;
    margin-top: 3px;
    z-index: 99;
    position: absolute;
    font-weight: 500;
    font-size: 12px;
    color: #E08821;
    display: flex;
    justify-content: center;
    align-items: center;
    img{
      width: 28px;
      height: 28px;
    }
  }
  .top-nav{
    width: 100%;
    height: 88px;
    display: flex;
    align-items: center;
    padding: 0 42px;
    box-sizing: border-box;
    .tips{
      width: 170px;
      height: 24px;
      background: #FFFFFF;
      border-radius: 30px 30px 30px 30px;
      font-weight: 500;
      font-size: 12px;
      color: #242B35;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .images{
      width: 60px;
      height: 60px;
      object-fit: cover;
    }
    span{
      font-weight: bold;
      font-size: 30px;
      color: #5A4CBB;
    }
  }
  .box-bottom{
    width: 375px;
    min-height: 619px;
    margin-top: 20px;
    background: linear-gradient( 180deg, #FFF0C9 0%, #D49188 100%);
    box-shadow: inset 0px 4px 4px 0px rgba(255,255,255,0.25);
    border-radius: 30px 30px 0px 0px;
    padding: 22px 18px;
    box-sizing: border-box;
    .btn-img{
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 400px;
      img{
        width: 200px;
      }
    }
    .box-nab{
      width: 343px;
      height: 32px;
      background: #FFFFFF;
      border-radius: 20px 20px 20px 20px;
      display: flex;
      align-items: center;
      padding: 2px;
      box-sizing: border-box;
      .item{
        font-weight: bold;
        font-size: 12px;
        color: #666666;
        width: 85px;
        height: 28px;
        border-radius: 20px 20px 20px 20px;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .active{
        background: #533DF1;
        color: #FFFFFF;
      }
    }

  }
}
</style>